import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Test from '@/pages/Test'
import Detail from '@/pages/Detail'
import ShopCart from '@/pages/ShopCart'
import AddCartSuccess from '@/pages/AddCartSuccess'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import MyOrder from '@/pages/Center/MyOrder'
import GroupOrder from '@/pages/Center/GroupOrder'

export default [
  {
    path: '/paysuccess',
    component: PaySuccess,
    beforeEnter: (to, from, next) => {
      if (from.path.indexOf('/pay') !== -1 || from.path === '/') {
        next()
      } else {
        next(false)
      }
    },
  },
  {
    path: '/center',
    component: Center,
    children: [
      {
        path: 'myorder',
        component: MyOrder,
      },
      {
        path: 'grouporder',
        component: GroupOrder,
      },
      {
        path: '',
        redirect: 'myorder',
      },
    ],
  },
  {
    path: '/home',
    component: Home,
  },
  {
    path: '/pay/:orderId',
    component: Pay,
    beforeEnter: (to, from, next) => {
      if (from.path.indexOf('/trade') !== -1 || from.path === '/') {
        next()
      } else {
        next(false)
      }
    },
  },
  {
    path: '/trade',
    component: Trade,
    beforeEnter: (to, from, next) => {
      if (
        from.path.indexOf('/shopcart') !== -1 ||
        from.path.indexOf('/login') !== -1 ||
        from.path === '/'
      ) {
        next()
      } else {
        next(false)
      }
    },
  },
  {
    path: '/shopcart',
    component: ShopCart,
  },
  {
    path: '/addcart_success',
    component: AddCartSuccess,
    name: 'addcartSuccess',
  },
  {
    path: '/detail/:goodsId',
    component: Detail,
  },
  {
    path: '/test',
    component: Test,
  },
  {
    path: '/login',
    component: () => import('@/pages/Login'),
    meta: {
      isHidden: true,
    },
  },
  {
    path: '/register',
    component: () => import('@/pages/Register'),
    meta: {
      isHidden: true,
    },
  },
  {
    path: '/search/:keyword?',
    component: () => import('@/pages/Search'),
    name: 'search',
    props: (route) => ({ ...route.params, ...route.query }),
    // props(route) {
    //   return {
    //     name: 'search',
    //     params: { keyword: route.content },
    //     query: { content: route.content },
    //   }
    // },
  },
  {
    path: '/',
    redirect: '/home',
  },
]
